package com.singbon.server.service;
import com.singbon.server.dao.AuthorizationDAO;
import com.singbon.server.dao.SysUserDAO;
import com.singbon.server.pojo.SysUser;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
/**
 */
@Service
public class SysUserService {
  /**
   * The Sys user dao.
   */
  @Resource
  public SysUserDAO sysUserDAO;
  /**
   * The Authorization dao.
   */
  @Resource
  public AuthorizationDAO authorizationDAO;
  /**
   * Select by id sys user.
   *
   * @param id the id
   * @return the sys user
   */
  public SysUser selectById(Integer id) {
    return sysUserDAO.selectById(id);
  }
  /**
   * Select by name sys user.
   *
   * @param name the name
   * @return the sys user
   */
  public SysUser selectByName(String name) {
    return sysUserDAO.selectByName(name);
  }
  /**
   * Login sys user.
   *
   * @param companyName the company name
   * @param loginName   the login name
   * @param loginPwd    the login pwd
   * @return the sys user
   */
  public SysUser login(String companyName, String loginName, String loginPwd) {
    return (SysUser) this.sysUserDAO.login(companyName, loginName, loginPwd);
  }
  /**
   * 获取出纳员列表
   *
   * @param companyId the company id
   * @return the list
   */
  public List<SysUser> selectCashierList(Integer companyId) {
    return this.sysUserDAO.selectCashierList(companyId);
  }
  /**
   * 删除
   *
   * @param operatorId the operator id
   * @throws Exception the exception
   */
  @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {RuntimeException.class, Exception.class})
  public void delete(Integer operatorId) throws Exception {
    this.authorizationDAO.deleteGroupUser(operatorId);
    this.sysUserDAO.delete(operatorId);
  }
  /**
   * 根据读卡器查询操作员
   *
   * @param companyId the company id
   * @param deviceNum the device num
   * @return the sys user
   */
  public SysUser selectSysUserByCardReader(Integer companyId, Integer deviceNum) {
    return this.sysUserDAO.selectSysUserByCardReader(companyId, deviceNum);
  }
  /**
   * 查询 admin
   *
   * @param companyId the company id
   * @return the sys user
   */
  public SysUser selectSysUserAdmin(Integer companyId) {
    return this.sysUserDAO.selectSysUserAdmin(companyId);
  }
}
